package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketLog;
import com.cskaoyan.market.db.domain.MarketLogExample;
import com.cskaoyan.market.db.mapper.MarketLogMapper;
import com.cskaoyan.market.service.AdminLogService;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 刘国兴
 * @description 日志系统管理
 */
@Service
public class AdminLogServiceImpl implements AdminLogService {

    @Autowired
    MarketLogMapper mapper;

    @Override
    @Transactional
    public List<MarketLog> list(Integer page, Integer limit , String sort, String order) {


        MarketLogExample example = new MarketLogExample();
        MarketLogExample.Criteria criteria = example.createCriteria();

        Map<String, Object> map = new HashMap<>();
       // parameterMap.forEach((key, value) -> map.put(key, StringUtils.join(value)));
        map.put("page",page);
        map.put("limit",limit);
        map.put("sort",sort);
        map.put("order",order);

        if (StringUtils.isNotEmpty((CharSequence) map.get("name"))) {
            criteria.andAdminLike("%"+map.get("name")+"%");
        }

        example.setOrderByClause(map.get("sort")+" "+map.get("order"));

        PageHelper.startPage((Integer) map.get("page"), (Integer) map.get("limit"));

        List<MarketLog> logList = mapper.selectByExample(example);
        return logList;
    }
}
